<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:cadastros="http://java.sun.com/jsf/composite/components/cadastros"
      >
    <ui:composition template="template.xhtml">
        <ui:define name="dialogs">

             <p:dialog header="Editar titulo" widgetVar="editTituloDialog" resizable="false" modal="true" width="600" >
                     <h:panelGroup id="editTitulo">
                            <cadastros:tituloComponent
                                 titulo="#{contasPagarBean.tituloSelected}"
                                 buttonText="Salvar"
                                 onclick_button_update=":contasPagarListform :growl"
                                 onclick_sair_javascript="editTituloDialog.hide()"
                                 buttonAction="#{contasPagarBean.save()}"
                                 />
                     </h:panelGroup>
            </p:dialog>

        </ui:define>


        <ui:define name="content">
            <h:form id="contasPagarListform">
              <h:panelGrid columns="2">
                        <h:outputText value="Numero do documento:" styleClass="formLabel" style="width: 120px"/>
                        <p:inputText id="docNumber" style="width: 300px" value="#{contasPagarBean.numberFilter}"
                                     onclick="jQuery(this).select()">
                            <p:ajax event="keyup" update="contasPagarList" />
                        </p:inputText>

                        <p:watermark for="docNumber" value="Digite o numero do documento" />
                    </h:panelGrid>
              <h:panelGroup id="contasPagarList">
                  <p:dataTable var="c" value="#{contasPagarBean.listTitulos()}"
                               paginator="true" rows="10" rowKey="#{c.id}"
                                     emptyMessage="Nenhuma conta encontrada"
                                     selectionMode="single" selection="#{contasPagarBean.tituloSelected}">

                            <p:ajax event="rowSelect" update="@this"/>

                            <f:facet name="header">
                                Lista de contas a pagar
                            </f:facet>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Numero documento" />
                                </f:facet>
                                <h:outputText value="#{c.numeroDocumento}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Fornecedor" />
                                </f:facet>
                                <h:outputText value="#{c.fornecedor.name}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Vencimento" />
                                </f:facet>
                                <h:outputText value="#{c.vencimento}" >
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Valor" />
                                </f:facet>
                                <h:outputText value="#{c.valor}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Pago" />
                                </f:facet>
                                <h:outputText rendered="#{c.isPago}" value="Sim" />
                                <h:outputText rendered="#{!c.isPago}" value="Não" />
                            </p:column>


                            <f:facet name="footer">
                                <p:commandButton icon="ui-icon ui-icon-plus" title="Adicionar conta a pagar" 
                                                 disabled="#{not sharedPermissionManagedBean.hasPermission('CRIAR_TITULO_AVULSO')}"/>
                                <p:commandButton icon="ui-icon ui-icon-pencil" title="Editar conta a pagar" update=":editTitulo" oncomplete="editTituloDialog.show()"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('EDITAR_TITULO_AVULSO')) or (contasPagarBean.tituloSelected.id == null)}"/>

                                <p:commandButton icon="ui-icon ui-icon-minus" title="Remover conta a pagar"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('REMOVER_TITULO_AVULSO')) or (contasPagarBean.tituloSelected.id == null)}"/>

                            </f:facet>
                        </p:dataTable>
                    </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>